package com.rdk.wechat.request.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rdk.exception.ServiceException;
import com.rdk.wechat.common.Constant;
import com.rdk.wechat.entity.WechatServiceUrlEntity;
import com.rdk.wechat.request.BaseWechatRquest;
import com.rdk.wechat.util.SystemConfig;

/**
 * 微信服务(CMS)基础请求服务接口实现类
 * 包含1个基础服务请求：获取access_token
 * 
 * @author wang_lei4
 *
 */
public class BaseWechatRquestImpl extends BaseRequest implements BaseWechatRquest{

	private Logger log = LoggerFactory.getLogger(BaseWechatRquestImpl.class);
	
	
	
	public BaseWechatRquestImpl() {
		super(null);
		we = new WechatServiceUrlEntity();
	}

	@Override
	public String getAccessToken(String appid, String secret, String accessType) {
		we.setServiceName(Constant.wechatServiceName.TOKEN);
		Map<String, String> paramMap = new HashMap<String, String>();
		
		//access_token=ACCESS_TOKEN
		paramMap.put("appID", appid);
		paramMap.put("appSecret", secret);
		paramMap.put("accessType", accessType);
		we.setParamMap(paramMap);
		String url = this.getUrl(we);
		
		//System.out.println(url);
		String jsonStr = null;
		try {
			jsonStr = httpClientUtil.getData(url);

		} catch (ServiceException e) {
			e.printStackTrace();
			
		}
		//String url = 
		return jsonStr;
	}
	
	public static void main(String[] args) {
		
		BaseWechatRquest base = new BaseWechatRquestImpl();
		String app_id = SystemConfig.readValue("app_id");
		String app_secret = SystemConfig.readValue("app_secret");
		String client = SystemConfig.readValue("client");
		
		System.out.println(base.getAccessToken(app_id, app_secret, client));
		
	}
	
	
}
